package com.mz.ozy.mvp.presenter;

import android.content.Context;

import com.mz.ozy.activity.find.DynamicDetailActivity;
import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.DynamicsDetailBean;
import com.mz.ozy.mvp.model.DynamicsDetailModel;
import com.mz.ozy.mvp.model.FollowModel;
import com.mz.ozy.mvp.view.DynamicsDetailContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;


public class DynamicsDetailPresenter extends BasePresenterImpl<DynamicsDetailContract.View> implements DynamicsDetailContract.Presenter {

    private DynamicsDetailModel mDynamicsDetailModel;
    private FollowModel mFollowModel;

    public DynamicsDetailPresenter() {
        mDynamicsDetailModel = new DynamicsDetailModel();
        mFollowModel = new FollowModel();
    }

    @Override
    public void queryDynamicsDetail(Context context, int did) {
        mDynamicsDetailModel.queryDynamicsDetail(context, did)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<DynamicsDetailBean>(mView) {

                    @Override
                    public void onSuccesss(DynamicsDetailBean result) {
                        mView.getFiendDynamicsDetail(result);
                    }
                });
    }

    @Override
    public void commentDynamics(Context context, int type, String cid, String pid, String uuid, String content) {
        mDynamicsDetailModel.commentDynamics(context, type, cid, pid, uuid, content)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {

                    @Override
                    public void onSuccesss(JSONObject result) {
                        mView.commentDynamicsSuccess(result);
                    }
                });
    }

    @Override
    public void followDynamics(Context context, int dynamicsID, int dynamicType) {
        mFollowModel.followTheObject(context, dynamicsID, dynamicType).
                compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {

                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.followDynamicsSuccess(jsonObject);
                    }
                });
    }

    public void deleteDynamics(Context context, int id) {
        mDynamicsDetailModel.deleteDynamics(context, id).
                compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {

                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.deleteDynamicsSuccess(jsonObject);
                    }
                });
    }
}
